<?php


namespace app\admin\model\base;


use app\BaseModel;

class StudentPractise extends BaseModel
{

    /**
     * 获取列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $orderby
     * @param string $field
     * @return array
     */
    public static function getList(array $where, int $page, int $limit, string $orderby = '', string $field = '*'): array
    {
        //查询
        $data = self::field($field)
            ->with(['student','practise'])
            ->where($where)
            ->order($orderby)
            ->paginate(['list_rows' => $limit, 'page' => $page], false)
            ->toArray();
        return $data;
    }

    public function practise(){
        return $this->hasOne(Practise::class,'id','practise_id')->field('name,id,special_id,start_time,end_time,time')->with(['special','practise_subject']);
    }

    public function student(){
        return $this->hasOne(Student::class,'id','student_id')->field('username,realname,id');
    }

    /**
     * 管理练习答题
     */
    public function studentPractiseSubject(){
        return $this->hasMany(StudentPractiseSubject::class,'student_practise_id','id');
    }

    /**
     * 管理练习题目
     */
    public function practiseSubject(){
        return $this->hasMany(PractiseSubject::class,'practise_id','id');
    }
}